
<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <link rel="stylesheet" href="prism.css">
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div id="header">
      <div class="doc-title"><a href="folktale.html"><span class="doc-title"><span class="product-name">Folktale</span><span class="version">v2.1.0</span></span></a><ul class="navigation"><li class="navigation-item"><a href="https://github.com/origamitower/folktale" title="">GitHub</a></li><li class="navigation-item"><a href="/docs/support/" title="">Support</a></li><li class="navigation-item"><a href="/docs/v2.1.0/contributing/" title="">Contributing</a></li></ul></div>
    </div>
    <div id="content-wrapper"><div id="content-panel"><h1 class="entity-title">(Anonymous)</h1><div class="highlight-summary"><div><p>Gets the eventual value of the task as a JavaScript&#39;s <code>Promise</code>.</p>
</div></div><h2 class="section-title">Documentation</h2><div class="documentation"><div><p>Gets the eventual value of the task as a JavaScript&#39;s <code>Promise</code>.</p>
<p>Since Promises don&#39;t have support for representing cancellations, Folktale&#39;s
tasks represent cancellation as a rejection with a special object. See the
documentation for Futures and Deferreds for more details.</p>
<h2 id="example-">Example:</h2>
<pre><code>const { task, of, rejected } = require(&#39;folktale/concurrency/task&#39;);

const result1 = await of(1).run().promise();
$ASSERT(result1 == 1);

try {
  const result2 = await rejected(1).run().promise();
  throw &#39;never happens&#39;;
} catch (error) {
  $ASSERT(error == 1);
}

try {
  const result3 = await task(r =&gt; r.cancel()).run().promise();
  throw &#39;never happens&#39;;
} catch (error) {
  const { Cancelled } = require(&#39;folktale/concurrency/future/_execution-state&#39;);
  $ASSERT(Cancelled.hasInstance(error));
}
</code></pre></div></div><div class="members"><h2 class="section-title" id="properties">Properties</h2></div></div><div id="meta-panel"><div class="meta-section"></div><div class="table-of-contents"><div class="meta-section-title">On This Page</div><ul class="toc-list level-1"><li class="toc-item"><span class="no-anchor">Documentation</span><ul class="toc-list level-2"><li class="toc-item"><a href="#example-" title="Example:"><div><p>Example:</p>
</div></a></li></ul></li><li class="toc-item"><a href="#properties">Properties</a><ul class="toc-list level-2"></ul></li></ul></div><div class="meta-section"><strong class="meta-section-title">Authors</strong><div class="meta-field"><strong class="meta-field-title">Authors</strong><div class="meta-field-value"><ul class="meta-list"></ul></div></div><div class="meta-field"><strong class="meta-field-title">Maintainers</strong><div class="meta-field-value"><ul class="meta-list"></ul></div></div></div></div></div>
    <script>
void function() {
  var xs = document.querySelectorAll('.documentation pre code');
  for (var i = 0; i < xs.length; ++i) {
    xs[i].className = 'language-javascript code-block';
  }
}()
    </script>
    <script src="prism.js"></script>
  </body>
</html>